
import { createRouter, createWebHistory } from 'vue-router';

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home.vue'),
  },
  {
    path: '/user',
    name: 'UserCenter',
    component: () => import('@/views/MicroAppContainer.vue'), // 子应用 user-center 的挂载容器
  },
  {
    path: '/forum',
    name: 'Forum',
    component: () => import('@/views/MicroAppContainer.vue'), // 子应用 forum 的挂载容器
  },
  {
    path: '/message',
    name: 'Message',
    component: () => import('@/views/MicroAppContainer.vue'), // 子应用 message 的挂载容器
  },
  {
    path: '/notification',
    name: 'Notification',
    component: () => import('@/views/MicroAppContainer.vue'), // 子应用 notification 的挂载容器
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
  },
  {
    path:'/user/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
  },
  {
    path: '/:pathMatch(.*)*', // 必须放在最后
    name: 'CatchAll',
    component: () => import('@/views/404.vue')
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});


//主应用使用的嵌套路由
router.beforeEach((to, from, next) => {
  if (!window.history.state.current) window.history.state.current = to.fullPath;
  if (!window.history.state.back) window.history.state.back = from.fullPath;
  // 手动修改history的state
  return next();
});

export default router;
